package org.lt.resume.service.resumeservice;

import java.util.List;

import org.lt.resume.dao.resumedao.ResumeDAO;
import org.lt.resume.domain.resume.Resume;
import org.lt.resume.service.resumeserviceInterface.ResumeServiceInterface;
import org.lt.resume.util.common.daoInterface.PagenateDAOInterface;

public class ResumeServiceImpl implements ResumeServiceInterface {

	/** **/
	private static final long serialVersionUID = 3132182267485845568L;

	private ResumeDAO resumeDAO;

	private PagenateDAOInterface pagenateDAO;

	private final int pagesize = 10;

	public void addResume(Resume resume){
		resumeDAO.addResume(resume);
	}

	public void updateResume(Resume resume) {
		resumeDAO.updateResume(resume);
	}

	public boolean deleteResumeByName(String username) {
		Resume resume = resumeDAO.findResumeByName(username);
		if (resume == null) {
			return false;
		}
		resumeDAO.deleteResume(resume);
		return true;
	}
	
	public boolean deleteResumeById(int id) {
		Resume resume = resumeDAO.findResumeById(id);
		if (resume == null) {
			return false;
		}
		resumeDAO.deleteResume(resume);
		return true;
	}

	public List searchResume(int currentpage){
		String sql = "from Resume as resume";
		String hql = "select count(*) from Resume as resume";
		int totalCount = pagenateDAO.getRowsCount(hql);
		if (totalCount < currentpage * pagesize) {

			currentpage = totalCount / pagesize;
		}
		List list = pagenateDAO.getData(currentpage, pagesize, sql);
		return list;
	}

	public List searchResumeForTable(String username) {

		List list = resumeDAO.finResumesByUsername(username);
		return list;
	}

	public ResumeDAO getResumeDAO() {
		return resumeDAO;
	}

	public void setResumeDAO(ResumeDAO resumeDAO) {
		this.resumeDAO = resumeDAO;
	}

	public PagenateDAOInterface getPagenateDAO() {
		return pagenateDAO;
	}

	public void setPagenateDAO(PagenateDAOInterface pagenateDAO) {
		this.pagenateDAO = pagenateDAO;
	}

}
